﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SmartSpace.UI.Silverlight.Theme;
using SmartSpace.UI.Silverlight;

namespace WorkSpace.Theme.Controls
{
    public partial class NavigationPart : SlView
    {
        private string _caption;

        private NavigatingEventHandler OnNavigate;

        public NavigationPart()
        {
            InitializeComponent();
        }

        public NavigationPart(SlNavigation navigation, List<SlNavigation> navigations, NavigatingEventHandler onNavigate)
            : this()
        {
            if (navigation == null)
            {
                _caption = "导航列表";
            }
            else
            {
                _caption = navigation.Name;
            }

            this._ctlListNavigation.ItemsSource = navigations;
            OnNavigate = onNavigate;
        }

        public override string GetCaption()
        {
            return _caption;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            SlNavigation navigation = btn.DataContext as SlNavigation;

            if (navigation.Children.Count == 0)
            {
                OnNavigate(this, new NavigatingEventArgs(navigation.Name, navigation.View));
            }
            else
            {
                this.SwitchView(new NavigationPart(navigation, navigation.Children, OnNavigate));
            }
        }
    }
}
